package svcnode.worker.session;

import soar.basic.*;

import svcnode.share.*;
import svcnode.worker.session.Session;

public class SessionCleaner extends Thread
{
    private String __CLASS__=SessionCleaner.class.getName();

    public SessionCleaner()
    {
    }

    public void run()
    {/*{{{*/
        final String __METHOD_="run";
        Session session=Session.getInstance();
        Operate operate=Operate.getInstance();
        final int CLEAN_INTERVAL=60*1000;
        int hash_idx=0;
        long last_clean=0;

        while(true)
        {
            long now=System.currentTimeMillis();
            if(now - last_clean > CLEAN_INTERVAL)
            {
                session.cleanTimeout(hash_idx);
                ++hash_idx;
                if(hash_idx == Session.HASH_SIZE)
                    hash_idx=0;
                last_clean=now;
            }

            if(operate.canShutdown())
            {
                operate.SessionCleanerStop();
                Errlog.add("%s.%s: SessionCleaner stop",
                        __CLASS__, __METHOD_);
                break;
            }

            try { Thread.sleep(1*1000); } catch(Exception e) {}
        }
    }/*}}}*/
}
